<?php
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.controller' );
    class admin_employeeController extends JController 
    {
        function __construct( $default = array())	
        {
            parent::__construct( $default );
	}
        
        function display($tpl = null) 
        {   
		$view = JRequest::getCmd('view');
		if(empty($view)) {
                    JRequest::setVar('view', 'dashboard');
		};
		parent::display($tpl);
	}
        
        //cho nhan vien nghi viec
        function del()
        {
            $get = JRequest::get('get',4);
            //print_r($get);die;
            $db = &JFactory::getDbo();
            $sql = "UPDATE #__hc_emplyee_profile
                    SET deleted = 1
                    WHERE id_user = '".$get['id']."' ";
            $db->setQuery($sql);
            $db->query();
            $sql = "UPDATE #__users
                    SET block = 1
                    WHERE id = '".$get['id']."' ";
            $db->setQuery($sql);
            $db->query();
            $this->setRedirect('index.php?option=com_admin_employee', 'Thành Công.');     
        }
        
        //them nhan vien lam viec
        function add_em()
        {
            $post = JRequest::get('post',4);
            $str = $post['year']."-".$post['month']."-".$post['day'];
            //echo $str;
            $date = date('Y-m-d',  strtotime($str));
            //echo $date;die;
            $row =  & JTable::getInstance('hc_emplyee_profile', 'Table');
            
            $row->id_user = $post['id_em'];
            $row->id_human = $post['cmnd'];
            $row->born = $date;
            $row->gender = $post['sex'];
            $row->mobile = $post['phone'];
            $row->address = $post['address'];
            $row->cv = $post['cv'];
            $row->deleted = 0;
            if (!$row->store()) { //thuc thi them record  neu co loi se hien thi
                                              JError::raiseError(500, $row->getError() );
                                                 }
                                                 
            $ro =  & JTable::getInstance('hc_access', 'Table');
            $ro->id_branch = $post['id_office'];
            $ro->id_user = $post['id_em'];
            $ro->id_function = $post['id_fun'];

            if (!$ro->store()) { //thuc thi them record  neu co loi se hien thi
                                              JError::raiseError(500, $ro->getError() );
                                                 }  
            $this->setRedirect('index.php?option=com_admin_employee', 'Thành Công.');     
        }
    }
    
?>